Skip to main content

How to use parental and grandparent information in analysis

The script below demonstrates how to use the variables BEFOLKNING_FAR_FNR and BEFOLKNING_MOR_FNR to untangle information about both parents and grandparents.

  1. You start with a normal personal dataset that contains links to parents.
  2. Then create a dataset consisting of parents, with links to their parents.
  3. The parental dataset is linked together with the personal dataset.
  4. You create a dataset consisting of grandparents.
  5. The grandparent dataset is linked with the personal dataset via identifiers for the parents' respective parents (= grandparents)
 require no.ssb.fdb:30 as db

// First create a person dataset with links to father and mother
create-dataset persondata
import db/INNTEKT_WYRKINNT 2019-01-01 as income
import db/BEFOLKNING_KJOENN as gender
import db/NUDB_BU 2019-01-01 as education
import db/BEFOLKNING_FAR_FNR as fnr_father
import db/BEFOLKNING_MOR_FNR as fnr_mother

// Then create a parent dataset with information including identifiers to parents' father and mother, and link to the person dataset via link keys for father and mother respectively
create-dataset parents
import db/INNTEKT_WYRKINNT 2019-01-01 as income_father
import db/NUDB_BU 2019-01-01 as education_father
clone-variables income_father -> income_mother
clone-variables education_father -> education_mother

import db/BEFOLKNING_FAR_FNR as fnr_paternal_grandfather
import db/BEFOLKNING_FAR_FNR as fnr_maternal_grandfather
import db/BEFOLKNING_MOR_FNR as fnr_paternal_grandmother
import db/BEFOLKNING_MOR_FNR as fnr_maternal_grandmother

merge income_father education_father fnr_paternal_grandfather fnr_paternal_grandmother into persondata on fnr_father
merge income_mother education_mother fnr_maternal_grandfather fnr_maternal_grandmother into persondata on fnr_mother

// Create a grandparent dataset with information, and link it to the person dataset via link keys for the respective grandparents
create-dataset grandparents
import db/INNTEKT_WYRKINNT 2019-01-01 as income_paternal_grandfather
import db/NUDB_BU 2019-01-01 as education_paternal_grandfather
clone-variables income_paternal_grandfather -> income_paternal_grandmother
clone-variables income_paternal_grandfather -> income_maternal_grandfather
clone-variables income_paternal_grandfather -> income_maternal_grandmother
clone-variables education_paternal_grandfather -> education_paternal_grandmother
clone-variables education_paternal_grandfather -> education_maternal_grandfather
clone-variables education_paternal_grandfather -> education_maternal_grandmother

merge income_paternal_grandfather education_paternal_grandfather into persondata on fnr_paternal_grandfather
merge income_paternal_grandmother education_paternal_grandmother into persondata on fnr_paternal_grandmother
merge income_maternal_grandfather education_maternal_grandfather into persondata on fnr_maternal_grandfather
merge income_maternal_grandmother education_maternal_grandmother into persondata on fnr_maternal_grandmother

// You have now created a dataset consisting of information about individuals and their parents and grandparents, and can run analyses of this
use persondata
summarize income income_father income_mother income_paternal_grandfather income_paternal_grandmother income_maternal_grandfather income_maternal_grandmother
barchart(mean) income income_father income_mother income_paternal_grandfather income_paternal_grandmother income_maternal_grandfather income_maternal_grandmother